<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<div id='common_query_win' style='display:none'></div>
<div id='commonQueryTable_html' style='display:none'></div>
<script>
function f_commonQuery(commonQueryGridTable,_afterSelected,_beforeSelect){
  var htmlDiv=Ext.get("commonQueryTable_html").dom;
  
  globalScope._model({tableName:commonQueryGridTable,quickWhere:' 1=2 '},function(responseText){
			    htmlDiv.innerHTML=responseText;
			    var span=Ext.get(commonQueryGridTable+"_columns").dom;
			    var modelColumns=Ext.decode(span.innerText);
			    var queryColumns=[];
			    Ext.each(Ext.ux.clone(modelColumns),function(col){
			      if(col.allowQuery){
			       col.allowBlank=true;
			       col.gridDisplay=true;
			       queryColumns.push(col);
			      } 
			    });	
			    var commonQueryForm = new Ext.quick.QuickForm({
			        labelAlign: 'right',
			        title: "<c:out value='${model.title}'/>--<fmt:message key="label.query"/>",
			        frame:true,
			        region:'north',
			        collapsible:true,
			        split:true,
			        autoScroll:true,
			        height:g_height*0.2,
			        buttons: [{
				         text:'<fmt:message key="button.query"/>',
				         handler:function(){
				         	var params={tableName:commonQueryGridTable};
				         	Ext.each(queryColumns,function(c){
				         	  params[c.name]=commonQueryForm.getForm().findField(c.name).getValue();
				         	});
						    if(typeof(_beforeSelect)=='function'){
						      _beforeSelect(params);
						    }				         	 
					      	 globalScope._model(params,function(responseText){
							     htmlDiv.innerHTML=responseText;
							     var span=Ext.get(commonQueryGridTable+"_columns").dom;
							     var columns=Ext.decode(span.innerText);
							     var commonQueryGrid= new Ext.quick.QuickGrid(commonQueryGridTable, {
								     id:'c_common_grid',
								     collapsible:true,
								     split:true,
								     stripeRows: true, 
								     enableDragDrop:false,
								     title:'grid',
								     clicksToEdit:1,
								     'remove':true,
								     height:g_height*85,
								     'smConfig':{}
							   },columns);
					           globalScope.grid.add(commonQueryGridTable,commonQueryGrid);
					           var p=Ext.getCmp('c_common_query_panel');
							   p.remove('c_common_grid');
							   p.add(commonQueryGrid);
							   p.doLayout();		        		
					      	});
				        }
				      },{
				        text:'<fmt:message key="button.reset"/>',
				        handler:function(){
				        	commonQueryForm.getForm().reset();
				        }
				      }
				    ]
				 },queryColumns,2);
  
		   	  Ext.get('common_query_win').dom.innerHTML=""; 
			  var commonQueryWin= new Ext.Window({
			    id:'c_win2',
			    el:'common_query_win',
			    layout:'border',
		        title:'请选择',
			    width:1000,
			    height:g_height*1.2,
			    closeAction:'hide',
			    buttonAlign:'center',
			    items: [commonQueryForm,{id:'c_common_query_panel',region:'center',layout:'fit',items:[{id:'c_common_grid'}] }],
			    buttons: [{
				        text:'<fmt:message key="button.conf"/>',
				        handler:function(){
		                    var m=globalScope.grid.get(commonQueryGridTable).getSelectionModel().getSelections(); 
						    if(m.length==0){
						      Ext.Msg.confirm('title','没有选择数据,确认吗',function(btn){
		                        if(btn=='yes'){
		                          commonQueryWin.hide();
		                        }
		                      });
		                      return;
						    }
						    if(typeof(_afterSelected)=='function'){
						      _afterSelected(m);
						    }
						    commonQueryWin.hide();
			            }
				      },{
				        text:'<fmt:message key="button.close"/>',
				        handler:function(){commonQueryWin.hide();}
				     }]
				});  
			   commonQueryWin.render(document.body);  
			   commonQueryWin.show(); 
  });
} 



</script>

